#coding=utf-8
from rest_framework import serializers
from rest_framework import viewsets
from rest_framework.decorators import list_route
from rest_framework.response import Response

from worldcup.apps.userModel.models import User, Game


class GameSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Game
        fields = ('id', 'home_team', 'away_team')



class GameViewSet(viewsets.ModelViewSet):
    queryset = Game.objects.all()
    serializer_class = GameSerializer

    # /api/game/getAllTeam/
    @list_route(methods=['get'])
    def getAllTeam(self, request, *args, **kwargs):
        result = set([])
        list1 = Game.objects.values("home_team").distinct().all()
        for game in list1:
            result.add(game["home_team"])
        return Response({'ret': 0, 'content': result})


